﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ProgNetComponents.Components
{
    public class CustomTypeDescriptorComponent : Component, ICustomTypeDescriptor
    {
        private string _Name;

        [Browsable(false)]
        public virtual string Name
        {
            get
            {
                if (this.Site != null)
                    return this.Site.Name;
                return _Name;
            }
            set
            {
                _Name = value;
                if (this.Site != null)
                    this.Site.Name = value;
            }
        }

        #region ICustomTypeDescriptor Members

        public virtual AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }

        public virtual string GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }

        public virtual string GetComponentName()
        {

            return TypeDescriptor.GetComponentName(this, true);
        }

        public virtual TypeConverter GetConverter()
        {

            return TypeDescriptor.GetConverter(this, true);

        }

        public virtual EventDescriptor GetDefaultEvent()
        {

            return TypeDescriptor.GetDefaultEvent(this, true);
        }

        public virtual PropertyDescriptor GetDefaultProperty()
        {

            return TypeDescriptor.GetDefaultProperty(this, true);
        }

        public virtual object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, true);
        }

        public virtual EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return GetEvents();
        }

        public virtual EventDescriptorCollection GetEvents()
        {
            //return TypeDescriptor.GetEvents(this, true);
            return ProgNetComponents.Design.EventInfoDescriptor.GetEvents(this);
        }

        public virtual PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return GetProperties();
        }

        public virtual PropertyDescriptorCollection GetProperties()
        {
            return ProgNetComponents.Design.PropertyInfoDescriptor.GetProperties(this);
        }

        public virtual object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }

        #endregion
    }
}
